<?php

namespace App\Http\Services;

use Illuminate\Support\Facades\DB;

class BaseService
{
    protected $model;

    public function __construct($model = '')
    {
        $this->model = $model;
    }


    //密码加密规则
    public function generatePassword($password = '', $salt = '')
    {
        $str = $password . $salt;
        return md5($str);
    }


    /*
     * 清空表
     * $table  表名
     * */
    public function clearTable($table)
    {
        DB::table($table)->delete();
    }

    //批量删除
    public function delModel($ids)
    {
        if (!is_array($ids)) {
            throw new InvalidRequestException('请传数组');
        }
        if (count($ids) == 0) {
            throw new InvalidRequestException('缺少id');
        }
        $result = $this->model->whereIn('id', $ids)->delete();
        return $result;
    }


    //获取当前用户id
    public function getCurrentUserId()
    {
        return $_SERVER['current_user']['id'];
    }




}
